<template>
    <a-modal :title="$t('快照配置')" v-model='isShow' @cancel='handleClose' width='480px' @ok='handleCreate'
        :cancelText="$t('Cancel')" :okText="$t('Sure')" :maskClosable='false' v-dragModal>
        <a-form-model ref="ruleForm" :model="form" :rules="rules" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-spin :spinning="loading">
                <a-form-model-item :label="$t('目录路径')" prop="path">
                    <a-input disabled v-model="form.path" :placeholder="$t('Enter') + $t('目录路径')" />
                    <!-- <a-button style="margin-left: 16px;" type='primary' @click="handleChoose">
                        {{ $t('浏览') }}
                    </a-button> -->
                </a-form-model-item>
                <a-form-model-item :label="$t('快照名')" prop="name">
                    <a-input v-model="form.name" :placeholder="$t('Enter') + $t('快照名')" />
                </a-form-model-item>
            </a-spin>
        </a-form-model>
        <!-- <chooseDirectory ref="directoryRef" @choose-directory="chooseDirectory" /> -->
    </a-modal>
</template>

<script>
import chooseDirectory from './chooseDirectory.vue';
export default {
    components: { chooseDirectory },
    data() {
        return {
            isShow: false,
            loading: false,
            labelCol: { span: 6 },
            wrapperCol: { span: 18 },
            form: {
                path: '',
                name: '',
                old_name: '',
            },
            rules: {
                path: [
                    { required: true, message: this.$t('Enter') + this.$t('目录路径'), trigger: 'blur' },
                ],
                name: [
                    { required: true, message: this.$t('Enter') + this.$t('快照名'), trigger: 'blur' },
                ],
            },
        };
    },
    methods: {
        handleCreate() {
            this.$refs.ruleForm.validate(async valid => {
                if (valid) {
                    this.loading = true
                    const { path, name, old_name } = this.form
                    const { data } = await this.$api.directory.modifySnapListApi({ path, name, old_name })
                    this.model(data.id) //返回模板
                    this.notice(data.id, data.params, data.flag) //通知列表显示
                    if (data.flag == '0') {
                        this.$emit('get-list')
                        this.handleClose()
                    }
                    this.loading = false
                } else {
                    return false;
                }
            });
        },
        handleClose() {
            this.$refs['ruleForm'].resetFields();
            this.isShow = false
        },
        handleChoose() {
            this.$refs.directoryRef.isShow = true
        },
        chooseDirectory(item) {
            console.log('item', item)
        },
    }
}
</script>
